package com.swt.controller.T_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Classroom;
import com.swt.domain.Club;
import com.swt.service.T_service.ClassroomService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ClassroomController {
    @Resource(name = "TClassroomService")
    private ClassroomService classroomService;
//    教室查询
    @RequestMapping("/queryClassroom")
    @ResponseBody
    public String query(HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        List<Classroom> classroomList = classroomService.classrommQuery(clubClubId);
        return JSON.toJSONString(classroomList);

    }

    //    根据场馆id查询教室
    @RequestMapping("/queryClassroom2")
    @ResponseBody
    public String query2Classroom(int id){
        List<Classroom> classroomList = classroomService.query2Classroom(id);
        return JSON.toJSONString(classroomList);

    }
//    教室添加
    @RequestMapping("/ClassroomAdd")
    @ResponseBody
    public String classAdd(String classroomName, String classroomCapacity, int shopid,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        boolean boo = classroomService.classrommAdd(classroomName,classroomCapacity,shopid,clubClubId);
        return JSON.toJSONString(boo);

    }
//教室删除
    @RequestMapping("/TClassroomDelete")
    @ResponseBody
    public String classDelete( int classid){

    boolean classDelete = classroomService.classDelete(classid);
    return JSON.toJSONString(classDelete);
    }



    public ClassroomService getClassroomService() {
        return classroomService;
    }

    public void setClassroomService(ClassroomService classroomService) {
        this.classroomService = classroomService;
    }
}
